<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
		if(!$this->session->userdata('user_id')){
			redirect('/',301);
		}
	}
	
	public function myprofile(){
		$data['title']	=	'My Profile';
		$data['user'] 	=	$this->users->getActive($this->session->userdata('user_id'));
		$data['action'] = 	'user/update';
		$data['content']= 	'profile-form';
		$this->load->view('index',$data);
		
	}
	
	function update(){
		if($this->input->post('save')):
              $this->users->getUpdate($this->session->userdata('user_id'));
              $this->session->set_flashdata('success','success');
              redirect($this->input->server('HTTP_REFERER'));
        else:
              $this->session->set_flashdata('error','error');
              redirect($this->input->server('HTTP_REFERER'));
        endif;	
	}
	
	public function password(){
		$data['title']	=	'Change Password';
		$data['user'] 	=	$this->users->getActive($this->session->userdata('user_id'));
		$data['action'] = 	'user/updatePassword';
		$data['content']= 	'password-form';
		$this->load->view('index',$data);
		
	}
	
	function updatePassword(){
		if($this->input->post('save')):
			 $password = sha1($this->input->post('old_password'));
			  if($this->users->checkUser($this->session->userdata('user_id'),$password)>0):
				 $this->users->getUpdatePassword($this->session->userdata('user_id'));
				 $this->session->set_flashdata('success','success');
				 redirect($this->input->server('HTTP_REFERER'));
			  else:
				 $this->session->set_flashdata('error','error');
				 redirect($this->input->server('HTTP_REFERER'));
			  endif;
             
        else:
              $this->session->set_flashdata('error','error');
              redirect($this->input->server('HTTP_REFERER'));
        endif;	
	}
	
	
	
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */